<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="admin.zipcode.zipcodeModel" %>
<jsp:useBean id="zipcodeDao" scope="page" class="admin.zipcode.zipcodeDao" />
<%
	String zip_code4 = request.getParameter("zip_code4") == null ? "" : request.getParameter("zip_code4");
	List list = new ArrayList();
	if(zip_code4 != null && !zip_code4.equals("")){
		list = zipcodeDao.getZipcode(zip_code4);
	}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="/admin/js/default.js"></script>
<link href="/admin/css/popdefault.css" rel="stylesheet" type="text/css" />
<!--[if lte IE 6]><link rel="stylesheet" href="/admin/css/forie6.css" type="text/css" /><![endif]-->
<script type="text/javascript" src="/admin/js/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
<!--
$(document).ready(function(){
	<%if(list != null && list.size() > 0){%>
	document.getElementById("address_list").style.display="block";
	<%}%>
	$('#zip_ok').click(function() {
		if(document.getElementById("address4").value != "" ){
			alert(opener.document.getElementById("zipcode1"));
		opener.document.getElementById("zipcode1").value = document.getElementById("zipcode1").value;
		opener.document.getElementById("zipcode2").value = document.getElementById("zipcode2").value;
		opener.document.getElementById("addr1").value = document.getElementById("address1").value;
		
		window.close();
		}else{
			alert("주소를 정확히 등록 하십시요.");
		}
	});
});
	function getView(zipcode,address1,address2,address3,address4,address5){
		
		opener.document.getElementById("zipcode1").value = zipcode.substring(0,3);
		opener.document.getElementById("zipcode2").value = zipcode.substring(3);
		opener.document.getElementById("addr1").value = address1+" "+address2+" "+address3+" "+address4+" "+address5;
		
		window.close();
	}
//-->
</script>
</head>
<body>
<form action="zipcode.jsp" name="frm" method="post">
<div id="bodywrap">
	<div class="all-wrap">
		<div id="right-wrap">
			<!--Contents Start-->
			<div id="content">
			<div class="list-search">
			<fieldset>
			<legend>주소 검색</legend>
			읍  면  동을 입력 하십시요. 
			<label for="searchText">검색</label>
			<input type="text" name="zip_code4" style="width:300px;" value="<%=zip_code4 %>"> <input type="submit" value="검색" class="btn-black"  />
			</fieldset>
			</div>
			<div id="address_view" style="display: none;">
			<div>
				우편 번호<input type="text" name="zipcode1" id="zipcode1" style="width:50px;"></input>
				 ~ <input type="text" name="zipcode2" id="zipcode2" style="width:50px;"></input>
			</div>
			<div>
				 <input type="text" name="address1" id="address1" style="width:50px;"/> 도
				 <input type="text" name="address2" id="address2" style="width:100px;"/>시 
			</div>
			<div>
				 <input type="text" name="address3" id="address3" style="width:100px;"/> 구
				<input type="text" name="address4" id="address4" style="width:100px;"/>번지
			</div>
			<div>
				상세 주소
				<input type="text" name="address5" id="address5" style="width:300px;"/>
			</div>
			<input type="button" name="zip_ok" id="zip_ok" value="확인"/>
			</div>
			<div id="address_list" style="display: none;">
			<%if(list != null && list.size() > 0){ %>
				<%for(int i=0; i<list.size(); i++){ %>
					<% zipcodeModel model = (zipcodeModel)list.get(i);%>
						<a href="javascript:getView('<%=model.getZip_code0()==null ? "" :model.getZip_code0() %>',
													'<%=model.getZip_code2()==null ? "" :model.getZip_code2() %>',
													'<%=model.getZip_code3()==null ? "" :model.getZip_code3() %>',
													'<%=model.getZip_code4()==null ? "" :model.getZip_code4() %>',
													'<%=model.getZip_code7()==null ? "" :model.getZip_code7() %>',
													'<%=model.getZip_code8()==null ? "" :model.getZip_code8() %>')" style="padding-bottom: 3px;"><%=model.getZip_code0()==null ? "" :model.getZip_code0() %>&nbsp;
						<%=model.getZip_code2()==null ? "" :model.getZip_code2()  %>&nbsp;
						<%=model.getZip_code3()==null ? "" :model.getZip_code3()  %>&nbsp;
						<%=model.getZip_code4()==null ? "" :model.getZip_code4()  %>&nbsp;
						<%=model.getZip_code5()==null ? "" :model.getZip_code5()  %>&nbsp;
						<%=model.getZip_code6()==null ? "" :model.getZip_code6()  %>&nbsp;
						<%=model.getZip_code7()==null ? "" :model.getZip_code7()  %>&nbsp;
						<%=model.getZip_code8() ==null ? "" :model.getZip_code8() %></a><br>
				<%} %>
			<%} %>
			</div>
			</div>
		</div>
	</div>
</div>
</form>
</body>
</html>